/*
 * CS_LOGIN_GUILD_MEMBER.cpp
 *
 *  Created on: 2014. 7. 31.
 *      Author: spencer(spencer@gamevile.com)
 */

#include "../../User.h"
#include "../../Command.h"
#include "../../Proxy.h"

#include "../protocol/Guild.h"

namespace ProjectZ { namespace NCommand {

void Command::CS_LOGIN_GUILD_MEMBER(User * pUser, ::Network::Packet * pPacket)
{
/*
	CS_GUILD_MYINFO						0x3228
	{
	}

	SC_GUILD_MYINFO						0x3229
	{
		s16		s16ack;				/// ACK_OK: 길드 있음
									/// ACK_GUILD_NOT_SIGNED : 길드 가입 안함

		u32		u32guild_seq;
		u8		u8member_type;				// 회원 구분 ( 0 : 미가입, 1 : 길드장, 10 : 길드원)

		str		strGuild_name;				//길드명

		//s8		s8Guild_icon;				//계급 아이콘 index (-1: 없음)

		u32		u32Guild_point;				//현재 길드 포인트
		u8		u8Guild_level;				//길드 등급

		u8		u32Guild_max_member;		//길드 최대 인원
		u8		u32Guild_current_member;	//길드 현재 인원

		//		u32		u32request_count;		// 가입요청한 유저 수 //기획삭제
	}
*/
	PREPARE_PACKET;

	if (0 >= pUser->GetUserInfo().guild_seq)
	{
		DEBUGLOG("%s> No Guild> user_seq: %d, guild_seq: %d"
				, __FUNCTION__
				, pUser->GetUserSeq(), pUser->GetUserInfo().guild_seq
				);

		::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();
		//*pAck << static_cast<int16_t>(ACK_UNKNOWN_ERROR);
		*pAck << static_cast<int16_t>(ACK_GUILD_NOT_SIGNED);
		pAck->MakePacket(CMD_SC_GUILD_MYINFO);
		pUser->Send(pAck);
		return;
	}

	LoginGuildMemberSyn syn;
	syn.user_seq	= pUser->GetUserSeq();
	syn.guild_seq	= pUser->GetGuildSeq();
	syn.level = pUser->GetCharacterInfo().level;
	syn.server_id = ::ProjectZ::Config::Instance().GetResourceDatabase()._channelUniqueIndex;
	syn.socialid = atoll(pUser->GetSocialID().c_str());
	syn.nickname = pUser->GetUserNickName().c_str();
	syn.profile_url = pUser->GetUserInfo().profile_url.c_str();


//	DEBUGLOG("%s> user_seq: %d, guild_seq: %d, level: %d, server_id: %d, socialid: %u, nickname: %s, profile_url: %s"
//			, __FUNCTION__
//			, syn.user_seq, syn.guild_seq
//			, syn.level, syn.server_id, syn.socialid, syn.nickname.c_str(), syn.profile_url.c_str()
//			);

	if (false == NProxy::SendGuildServer(pUser, syn))
	{
		::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();
		*pAck << static_cast<int16_t>(ACK_UNKNOWN_ERROR);
		pAck->MakePacket(CMD_SC_GUILD_MYINFO);
		pUser->Send(pAck);
		return;
	}
}

} /*NCommand*/ } /*ProjectZ*/
